// API utility with environment-based configuration
// This is the original fetch-based API client
import config from '../config';

// New axios-based request utility
import request from './request';

class ApiClient {
  private baseUrl: string;

  constructor() {
    this.baseUrl = config.api.baseUrl;
  }

  public getBaseUrl(): string {
    return this.baseUrl;
  }

  // Original fetch-based GET method
  public async get<T>(endpoint: string): Promise<T> {
    const url = `${this.baseUrl}${endpoint}`;
    const response = await fetch(url);
    
    if (!response.ok) {
      throw new Error(`API request failed: ${response.statusText}`);
    }
    
    return response.json();
  }

  // New axios-based GET method (alternative)
  public async getWithAxios<T>(endpoint: string): Promise<T> {
    return request.get(endpoint);
  }
}

const apiClient = new ApiClient();
export default apiClient;